USE MASTER
 IF EXISTS (SELECT * FROM SYSDATABASES WHERE name = 'VnaManageBank')
 DROP DATABASE VnaManageBank
GO
CREATE DATABASE VnaManageBank
GO
USE VnaManageBank
GO
--						1.Account
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Account]') AND type in (N'U'))
DROP TABLE [dbo].[Account]
GO
CREATE TABLE Account
(
	AccountID INT PRIMARY KEY IDENTITY,
	UserName nVARCHAR(200) NOT NULL,
	PassWord nVARCHAR(200) NOT NULL,
	Administrator BIT,
	PermissionName nvarchar(50),
	LockedAccount BIT,
	EmployeeCode nVARCHAR(50)
)
GO
--						2.Permission
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Permission]') AND type in (N'U'))
DROP TABLE [dbo].[Permission]
GO
CREATE TABLE Permission
(
	PermissionID INT PRIMARY KEY IDENTITY,
	PermissionName nVARCHAR(50) NOT NULL,
	FormName nVARCHAR(200) NOT NULL,
	PerAdd BIT,
	PerEdit BIT,
	PerDelete BIT,
	PerView BIT
)
GO
--						3.NhanVien
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[NhanVien]') AND type in (N'U'))
DROP TABLE [dbo].[NhanVien]
GO
CREATE TABLE NhanVien
(
	NhanVienID INT PRIMARY KEY IDENTITY,
	MaNhanVien nVARCHAR(50),
	TenNhanVien nVARCHAR(200),
	MaChucVu nVARCHAR(50),
	GioiTinh BIT,
	NgaySinh Datetime,
	SCMND nVARCHAR(200),
	DiaChi nVARCHAR(200),
	SoDienThoai nVARCHAR(200)
)
GO
--						4.ChucVu
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ChucVu]') AND type in (N'U'))
DROP TABLE [dbo].[ChucVu]
GO
CREATE TABLE ChucVu
(
	ChucVuID INT PRIMARY KEY IDENTITY,
	MaChucVu nVARCHAR(50),
	TenChucVu nVARCHAR(200)
)
GO
--						5.KhachHang
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KhachHang]') AND type in (N'U'))
DROP TABLE [dbo].[KhachHang]
GO
CREATE TABLE KhachHang
(
	KhachHangID INT PRIMARY KEY IDENTITY,
	MaKhachHang nVARCHAR(50),
	TenKhachHang nVARCHAR(200),
	SCMND nVARCHAR(200),
	NoiCap nVARCHAR(200),
	NgayCap Datetime,
	SoDienThoai nVARCHAR(200)
)
GO
--						6.SoTietKiem
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SoTietKiem]') AND type in (N'U'))
DROP TABLE [dbo].[SoTietKiem]
GO
CREATE TABLE SoTietKiem
(
	SoTietKiemID INT PRIMARY KEY IDENTITY,
	MaSoTietKiem nVARCHAR(50),
	MaLoaiTietKiem nVARCHAR(50),
	MaLoaiTien nVARCHAR(50),
	MaKyHan nVARCHAR(50),
	MaNhanVien nVARCHAR(50),
	MaKhachHang nVARCHAR(50)
)
GO	
--						7.TaiKhoan
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TaiKhoan]') AND type in (N'U'))
DROP TABLE [dbo].[TaiKhoan]
GO
CREATE TABLE TaiKhoan
(
	TaiKhoanID INT PRIMARY KEY IDENTITY,
	SoHieuTaiKhoan nVARCHAR(50),
	NgayCapNhat Datetime,
	SoDuDau float
)
GO
--						8.LaiSuat
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LaiSuat]') AND type in (N'U'))
DROP TABLE [dbo].[LaiSuat]
GO
CREATE TABLE LaiSuat
(
	LaiSuatID INT PRIMARY KEY IDENTITY,
	MaLoaiTien nVARCHAR(50),
	MucLaiSuat float
)
GO
--						9.KyHan
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[KyHan]') AND type in (N'U'))
DROP TABLE [dbo].[KyHan]
GO
CREATE TABLE KyHan
(
	KyHanID INT PRIMARY KEY IDENTITY,
	MaKyHan nVARCHAR(50),
	TenKyHan nVARCHAR(200)
)
GO
--						10.LoaiTietKiem
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LoaiTietKiem]') AND type in (N'U'))
DROP TABLE [dbo].[LoaiTietKiem]
GO
CREATE TABLE LoaiTietKiem
(
	LoaiTietKiemID INT PRIMARY KEY IDENTITY,
	MaLoaiTietKiem nVARCHAR(50),
	TenLoaiTietKiem nVARCHAR(200),
	MaLoaiTien nVARCHAR(50),
	MaKyHan nVARCHAR(50),
	SoHieuTaiKhoan nVARCHAR(50)
)
GO
--						11.LoaiTien
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[LoaiTien]') AND type in (N'U'))
DROP TABLE [dbo].[LoaiTien]
GO
CREATE TABLE LoaiTien
(
	LoaiTienID INT PRIMARY KEY IDENTITY,
	MaLoaiTien nVARCHAR(50),
	TenLoaiTien nVARCHAR(200)
)
GO
--
